
USE [CamelioDB]
GO

/****** Object:  StoredProcedure [proc_AdminLoadByPrimaryKey]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_AdminLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_AdminLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_AdminLoadByPrimaryKey]
(
	@AdminID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[AdminID],
		[AminUserName],
		[AdminPassword],
		[AdminType]
	FROM [Admin]
	WHERE
		([AdminID] = @AdminID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_AdminLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_AdminLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_AdminLoadAll]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_AdminLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_AdminLoadAll];
GO

CREATE PROCEDURE [proc_AdminLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[AdminID],
		[AminUserName],
		[AdminPassword],
		[AdminType]
	FROM [Admin]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_AdminLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_AdminLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_AdminUpdate]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_AdminUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_AdminUpdate];
GO

CREATE PROCEDURE [proc_AdminUpdate]
(
	@AdminID int,
	@AminUserName nvarchar(250) = NULL,
	@AdminPassword nvarchar(50) = NULL,
	@AdminType nvarchar(50) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Admin]
	SET
		[AminUserName] = @AminUserName,
		[AdminPassword] = @AdminPassword,
		[AdminType] = @AdminType
	WHERE
		[AdminID] = @AdminID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_AdminUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_AdminUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_AdminInsert]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_AdminInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_AdminInsert];
GO

CREATE PROCEDURE [proc_AdminInsert]
(
	@AdminID int = NULL output,
	@AminUserName nvarchar(250) = NULL,
	@AdminPassword nvarchar(50) = NULL,
	@AdminType nvarchar(50) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Admin]
	(
		[AminUserName],
		[AdminPassword],
		[AdminType]
	)
	VALUES
	(
		@AminUserName,
		@AdminPassword,
		@AdminType
	)

	SET @Err = @@Error

	SELECT @AdminID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_AdminInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_AdminInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_AdminDelete]    Script Date: 21/3/2015 6:45:12 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_AdminDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_AdminDelete];
GO

CREATE PROCEDURE [proc_AdminDelete]
(
	@AdminID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Admin]
	WHERE
		[AdminID] = @AdminID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_AdminDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_AdminDelete Error on Creation'
GO
